import {request,connectWebSocket} from "../utils/request"

/**
 * 请求示例
 */

export const messageHistory=(userId1:String, userId2: String,page:number=0,size:number=20) =>{
    return request({
        url: '/messages/history',
        method: 'get',
        data: {
            userId1,
            userId2,
            page,
            size
        },
        withCredentials: true // 携带cookie
    })
};
    export const getMessageList=(userId:String) =>{
    return request({
        url: '/messages/messagelist',
        method: 'get',
        data: {
            userId
        },
        withCredentials: true // 携带cookie
    })
}

/**
 * 建立WebSocket聊天连接
 */
export const connectChatWebSocket = (
    toUserId: string,
    currentUserId: string
) => {
    return connectWebSocket(`/ws/chat/${toUserId}/${currentUserId}`);
};

/**
 * 建立WebSocket聊天连接
 */
export const connectMessageListWebSocket = (
    userId: string,
) => {
    return connectWebSocket(`/ws/notifications/${userId}`);
};